package com.aqie.easy.hash;

/**
 * 806. 写字符串需要的行数
 */
public class NumberOfLines {
    public int[] numberOfLines(int[] widths, String S) {
        int line = 1;
        int last = 0;

        for (int i = 0; i < S.length(); i++){
           last += widths[S.charAt(i) - 'a'];
           if(last >= 100){
               line++;

               if(last == 100){
                   last = 0;
               }else{
                   last = widths[S.charAt(i) - 'a'];
               }
           }
        }

        return new int[]{line, last};

    }

    public static void main(String[] args) {
        String S = "bbbcccdddaaa";

        int[] widths = {4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10};
        int sum = 0;
        for (int i = 0; i < S.length(); i++){
            sum += widths[S.charAt(i) - 'a'];
        }
        System.out.print(sum);
    }
}
